package vn.edu.saigontech.ncms.model.result;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.OptimisticLockType;

import vn.edu.saigontech.ncms.model.BaseEntity;
import vn.edu.saigontech.ncms.model.info.AbstractReceipt;
import vn.edu.saigontech.ncms.model.info.Student;
import vn.edu.saigontech.ncms.model.program.Level;
import vn.edu.saigontech.ncms.model.user.User;

@Entity
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true, optimisticLock = OptimisticLockType.ALL)
@Table(name = "ncms_moveup_test")
@SuppressWarnings("serial")
public class MoveUpTest extends BaseEntity {
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "student_id", nullable = false)
	private Student student;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "level_id")
	private Level level;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "cashier_id")
	private User cashier;

	@Column(name = "date")
	@Temporal(TemporalType.DATE)
	private Date date;

	@Column(name = "register_date")
	@Temporal(TemporalType.DATE)
	private Date registerDate;

	@Column(name = "receipt_no")
	private String receiptNo;

	@Column(name = "fee")
	private Double fee;

	@Column(name = "written_score")
	private Double writtenScore;

	@Column(name = "speaking_score")
	private Double speakingScore;

	@Column(name = "listening_score")
	private Double listeningScore;

	@Column(name = "grammar_score")
	private Double grammarScore;

	@Column(name = "reading_score")
	private Double readingScore;

	@Column(name = "active")
	private Boolean active = true;

	@Column(name = "comment", length = 4000)
	private String comment;

	@Transient
	private Date fromTestDate;

	@Transient
	private Date toTestDate;
	
	public boolean isValid() {
		for (AbstractReceipt receipt : this.student.getOfferingReceipts()) {
			if(receipt.getOffering().getLevel().equals(this.level)) {
				return true;
			}
		}
		return false;
	}

	public Student getStudent() {
		return student;
	}

	public void setStudent(Student student) {
		this.student = student;
	}

	public Level getLevel() {
		return level;
	}

	public void setLevel(Level level) {
		this.level = level;
	}

	public User getCashier() {
		return cashier;
	}

	public void setCashier(User cashier) {
		this.cashier = cashier;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Date getRegisterDate() {
		return registerDate;
	}

	public void setRegisterDate(Date registerDate) {
		this.registerDate = registerDate;
	}

	public String getReceiptNo() {
		return receiptNo;
	}

	public void setReceiptNo(String receiptNo) {
		this.receiptNo = receiptNo;
	}

	public Double getFee() {
		return fee;
	}

	public void setFee(Double fee) {
		this.fee = fee;
	}

	public Double getWrittenScore() {
		return writtenScore;
	}

	public void setWrittenScore(Double writtenScore) {
		this.writtenScore = writtenScore;
	}

	public Double getSpeakingScore() {
		return speakingScore;
	}

	public void setSpeakingScore(Double speakingScore) {
		this.speakingScore = speakingScore;
	}

	public Double getListeningScore() {
		return listeningScore;
	}

	public void setListeningScore(Double listeningScore) {
		this.listeningScore = listeningScore;
	}

	public Double getGrammarScore() {
		return grammarScore;
	}

	public void setGrammarScore(Double grammarScore) {
		this.grammarScore = grammarScore;
	}

	public Double getReadingScore() {
		return readingScore;
	}

	public void setReadingScore(Double readingScore) {
		this.readingScore = readingScore;
	}

	public Boolean getActive() {
		return active;
	}

	public void setActive(Boolean active) {
		this.active = active;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public Date getFromTestDate() {
		return fromTestDate;
	}

	public void setFromTestDate(Date fromTestDate) {
		this.fromTestDate = fromTestDate;
	}

	public Date getToTestDate() {
		return toTestDate;
	}

	public void setToTestDate(Date toTestDate) {
		this.toTestDate = toTestDate;
	}
}